import {defineConfig} from 'vite'
import vue from '@vitejs/plugin-vue'

import * as path from 'path'
import Components from 'unplugin-vue-components/vite'
import AutoImport from 'unplugin-auto-import/vite'
import {AntDesignVueResolver, ElementPlusResolver, VantResolver} from 'unplugin-vue-components/resolvers'

const projectRootDir = path.resolve(__dirname)

// https://vitejs.dev/config/
export default ({mode, command}) => {
  return defineConfig({
    envDir: path.resolve(projectRootDir, 'env'),
    base: '/context/', // 二级目录
    server: {
      port:3005,
      proxy: {
        '/api/': {
          //target: 'http://127.0.0.1:5000',
          target: 'https://apaas-dev6270.aedev.feishuapp.cn/ae/public/package_ywr1it__c',
          changeOrigin: true,
          rewrite: (path) => path.replace(/^\/api/, ''),
        },
      },
    },
    resolve: {
      alias: [
        {
          find: '@',
          replacement: path.resolve(projectRootDir, 'src'),
        },
      ],
    },
    plugins: [
      vue(),
      Components({
        resolvers: [VantResolver(), AntDesignVueResolver(), ElementPlusResolver()],
      }),
      AutoImport({
        include: [
          /\.[tj]sx?$/, // .ts, .tsx, .js, .jsx
          /\.vue$/,
          /\.vue\?vue/, // .vue
          /\.md$/ // .md
        ],
        imports: [
          'vue',
          'vue-router',
          {
            '@vueuse/core': [
              'useMouse',
              ['useFetch', 'useMyFetch']
            ],
            axios: [
              ['default', 'axios']
            ]
          }
        ],
        resolvers: [ElementPlusResolver()],
      })
    ]
  })
}
